<template>
	<view class="content">

		<uni-row class="demo-uni-row" v-for="(item,index) in resList" :key="index">
			<uni-col :span="8" :style="{ backgroundColor:'#649FF3', height: (item.length*100)+'px' }">
				<view class="demo-uni-col dark" style="background-color: #649FF3;">
					<view style="color: #fff;font-size: 20px;margin-top: 20px;margin-left: 20px;">{{index}}班</view>
				</view>
			</uni-col>
			<uni-col :span="16">
				<view class="demo-uni-col light" v-for="(item2,index2) in item" :key="index2">
					<u-card :title="item2.project_name" padding="30" margin="26rpx" :sub-title="'学分：'+item2.credit+''">
					</u-card>
				</view>
			</uni-col>
		</uni-row>
		<!-- 	<view v-for="(item,index) in resList" :key="index">
			<view>
				<view style="text-align: center;">{{index}}</view>
				<view v-for="(item2,index2) in item" :key="index2">
					<u-card :title="item2.project_name" padding="30" margin="26rpx" :sub-title="item2.credit+''">
					
					</u-card>
				</view>
			</view>

		</view> -->
	</view>
</template>
<script>
	import {
		getCreditByuserId
	} from '@/api/jz/student/info.js'
	import {
		getInfoId
	} from '@/utils/auth';

	export default {
		data() {
			return {
			
				mySignInList: [],
				CourseInfoSignList: [],
				student: null,
				resList: []
			}
		},
		onLoad(data) {
			if (data.data) {
				this.student = JSON.parse(decodeURIComponent(data.data))
			}

		},
		methods: {

			getCourseInfoSignByStudentIdFun() {
				let studentId = null;
				if (this.student) {
					studentId = this.student.id
				} else {
					studentId = getInfoId();
				}
				getCreditByuserId(studentId).then((res) => {
					if (res.code == 200) {
						this.CourseInfoSignList = res.data
						this.resList = this.groupBy(this.CourseInfoSignList, 'class_name')

					}
				})
			},

			groupBy(arr, property) {
				return arr.reduce(function(cur, obj) {
					var key = obj[property];
					if (!cur[key]) {
						cur[key] = [];
					}
					cur[key].push(obj);
					return cur;
				}, {});
			}
		},





		mounted() {

			this.getCourseInfoSignByStudentIdFun();
		}
	}
</script>

<style>
</style>
